<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="./layui/css/layui.css"  media="all">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>表单集合演示</legend>
</fieldset>
 
<div class="layui-form-item">
 <label class="layui-form-label"></label>
<div class="layui-upload">
  <button type="button" class="layui-btn" id="test2">多图片上传</button> 
  <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
  <input type="hidden" value="" id="">
    预览图：
    <div class="layui-upload-list" id="demo2"></div>
 </blockquote>
</div>


    <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>	


</body>
</html>
<script src="./layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'upload'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,upload = layui.upload
  // ,layedit = layui.layedit
  // ,laydate = layui.laydate;
  
 
 

  
  //监听提交
  form.on('submit(demo1)', function(data){
    // layer.alert(JSON.stringify(data.field), {
    //   title: '最终的提交信息'
    // })
    return false;
  });

   //多图片上传
  upload.render({
    elem: '#test2'
    ,url: 'http://127.0.0.1/localhost/linaxi/php/public/index.php/index/admin/adds'
    ,multiple: true
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){
        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
      });
    }
    ,done: function(res){
      //上传完毕
      $().val(res.data.src)
    }
  });
 
 
  

  
});
</script>
